package leetcode.code0309;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int maxProfit(int[] prices) {
		int len = prices.length;
		int[] dp = new int[len];
		for (int i = 1; i < len; i++) {
			int max = Integer.MIN_VALUE;
			int pricei = prices[i];
			for (int j = 0; j < i; j++) {
				int tmp = j - 2 >= 0 ? dp[j - 2] : 0;
				max = Math.max(max, tmp + pricei - prices[j]);
			}
			dp[i] = Math.max(dp[i - 1], max);
		}
		return dp[len - 1];
	}

	@Override
	public void debug1() {
		HelpDebug.compare(3, this.maxProfit(HelpDebug.str2array3("[1,2,3,0,2]")));

	}

	@Override
	public void debug2() {
		HelpDebug.compare(32, this.maxProfit(HelpDebug.str2array3("[1,2,3,0,2,1,0,2,3,6,2,3,9,4,14,3,20]")));

	}

	@Override
	public void debug3() {
		HelpDebug.compare(3, this.maxProfit(HelpDebug.str2array3("[1,2,3,0,2,1]")));

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
